<?php
declare(strict_types=1);

namespace App\TCP;

use App\GlobalData;

class ReceiveHandler
{
    public function handle(\Swoole\Server $server, int $fd, int $reactor_id, string $data): void
    {
        $cmds = explode("\n", $data);
        foreach ($cmds as $cmd) {
            var_dump($cmd);
            // 处理命令
            $datas = explode(' ', $cmd);
            switch (ucfirst($datas[0])) {
                case 'Auth':
//                    $server->send($fd, "OK\n");
                    unset(GlobalData::getMap()['wait_cons'][$fd]);
                    break;
                default:
                    $server->send($fd, "ERR\n");
                    return;
            }
            $server->send($fd, "OK\n");
        }
    }
}